#!/usr/bin/env python

Import('envs', 'aspects', 'libraries')

substs = {
        'GLWIN': aspects['glwin'],
        'GLTYPE': aspects['gltype'],
        'LIBRARIES': ''
        }

soname_map = {
    'libGL.so': 'libGL.so.1'
}

for lib in libraries:
    if aspects['binfmt'] == 'pe':
        # TODO need a better way to do this
        mangled = r'c:\\windows\\system32\\' + lib + '.dll'
    else:
        mangled = lib + envs['host'].subst('$SHLIBSUFFIX')
        if mangled in soname_map:
            mangled = soname_map[mangled]
    substs['LIBRARIES'] += 'LIBRARY ' + mangled + '\n'

callapi = aspects['callapi']
if callapi is None or callapi == '':
    substs['CALLAPI'] = ''
else:
    substs['CALLAPI'] = 'CALLAPI ' + callapi

envs['tu'].SubstFile('main.bc', 'main.bc.in', substs)
